﻿<UserControl 
    x:Class="Sidvall.UI.Wpf.Controls.PageItemControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:vms="clr-namespace:Sidvall.UI.Entities;assembly=Sidvall.UI"
    xmlns:local="clr-namespace:Sidvall.UI.Wpf.Controls" 
    xmlns:ig="http://schemas.infragistics.com/xaml" 
    xmlns:igWPF="http://schemas.infragistics.com/xaml/wpf" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Controls="clr-namespace:Sidvall.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters"
    xmlns:b="clr-namespace:Sidvall.UI.Wpf.Controls" 
    mc:Ignorable="d" 
    d:DesignHeight="50" d:DesignWidth="400">

    <UserControl.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True" />
        <Converters:StringToVisibilityConverter x:Key="NotStringToVisibilityConverter" Not="True" />
        <Converters:MultiStringToBooleanConverter x:Key="NotMultiStringToBooleanConverter" Not="True" />
    </UserControl.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:PageItem}}" 
          DataContext="{Binding PageItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PageItemControl}}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel  Orientation="Horizontal" Margin="0,5,0,0">
            <Button Padding="0" IsEnabled="{Binding CanPageBack}" ToolTip="Första sidan" Click="PageFirstButton_Click">
                <Image Source="/Sidvall.UI.Wpf;component/Images/GoFirst.png" Width="24" />
            </Button>
            <Button Padding="0" IsEnabled="{Binding CanPageBack}" ToolTip="Föregående sida" Margin="5,0,0,0" Click="PageBackButton_Click">
                <Image Source="/Sidvall.UI.Wpf;component/Images/GoPrevious.png" Width="24" />
            </Button>

            <Button Padding="0" Content="{Binding PageItemStart1}" Margin="5,0,0,0" Click="PageItemStart1_Click" MinWidth="24"
                    Visibility="{Binding PageItemStart1, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemStart1" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemStart2}" Margin="5,0,0,0" Click="PageItemStart2_Click" MinWidth="24"
                    Visibility="{Binding PageItemStart2, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemStart2" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemStart3}" Margin="5,0,0,0" Click="PageItemStart3_Click" MinWidth="24"
                    Visibility="{Binding PageItemStart3, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemStart3" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemStart4}" Margin="5,0,0,0" Click="PageItemStart4_Click" MinWidth="24"
                    Visibility="{Binding PageItemStart4, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemStart4" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>

            <TextBlock Padding="0" Text="..." VerticalAlignment="Center" Margin="5,0,0,0" 
                       Visibility="{Binding HasPageItemStartGap, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" />

            <Button Padding="0" Content="{Binding PageItemPrevious1}" Margin="5,0,0,0" Click="PageItemPrevious1_Click" MinWidth="24"
                    Visibility="{Binding PageItemPrevious1, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemPrevious2}" Margin="5,0,0,0" Click="PageItemPrevious2_Click" MinWidth="24"
                    Visibility="{Binding PageItemPrevious2, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemPrevious3}" Margin="5,0,0,0" Click="PageItemPrevious3_Click" MinWidth="24"
                    Visibility="{Binding PageItemPrevious3, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemPrevious4}" Margin="5,0,0,0" Click="PageItemPrevious4_Click" MinWidth="24"
                    Visibility="{Binding PageItemPrevious4, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />

            <Button Padding="0" Content="{Binding CurrentPage}" Margin="5,0,0,0" IsEnabled="False" MinWidth="24"
                    Visibility="{Binding HasPageItemCurrentPage, Converter={StaticResource NotBooleanToVisibilityConverter}, Mode=OneWay}"/>

            <Button Padding="0" Content="{Binding PageItemNext1}" Margin="5,0,0,0" Click="PageItemNext1_Click" MinWidth="24"
                    Visibility="{Binding PageItemNext1, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemNext2}" Margin="5,0,0,0" Click="PageItemNext2_Click" MinWidth="24"
                    Visibility="{Binding PageItemNext2, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemNext3}" Margin="5,0,0,0" Click="PageItemNext3_Click" MinWidth="24"
                    Visibility="{Binding PageItemNext3, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />
            <Button Padding="0" Content="{Binding PageItemNext4}" Margin="5,0,0,0" Click="PageItemNext4_Click" MinWidth="24"
                    Visibility="{Binding PageItemNext4, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}" />

            <TextBlock Padding="0" Text="..." VerticalAlignment="Center" Margin="5,0,0,0" 
                       Visibility="{Binding HasPageItemEndGap, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" />

            <Button Padding="0" Content="{Binding PageItemEnd1}" Margin="5,0,0,0" Click="PageItemEnd1_Click" MinWidth="24"
                    Visibility="{Binding PageItemEnd1, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemEnd1" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemEnd2}" Margin="5,0,0,0" Click="PageItemEnd2_Click" MinWidth="24"
                    Visibility="{Binding PageItemEnd2, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemEnd2" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemEnd3}" Margin="5,0,0,0" Click="PageItemEnd3_Click" MinWidth="24"
                    Visibility="{Binding PageItemEnd3, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemEnd3" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Padding="0" Content="{Binding PageItemEnd4}" Margin="5,0,0,0" Click="PageItemEnd4_Click" MinWidth="24"
                    Visibility="{Binding PageItemEnd4, Converter={StaticResource NotStringToVisibilityConverter}, Mode=OneWay}">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource NotMultiStringToBooleanConverter}">
                        <Binding Path="PageItemEnd4" />
                        <Binding Path="CurrentPage" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>

            <Button Padding="0" IsEnabled="{Binding CanPageForward}" ToolTip="Nästa sida" Margin="5,0,0,0" Click="PageForwardButton_Click">
                <Image Source="/Sidvall.UI.Wpf;component/Images/GoNext.png" Width="24" />
            </Button>
            <Button Padding="0" IsEnabled="{Binding CanPageForward}" ToolTip="Sista sidan" Margin="5,0,0,0" Click="PageLastButton_Click">
                <Image Source="/Sidvall.UI.Wpf;component/Images/GoLast.png" Width="24" />
            </Button>
        </StackPanel>
    </Grid>
</UserControl>
